package com.itclass.auth.pojo.dto;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.baomidou.mybatisplus.annotation.TableField;
import com.itclass.auth.pojo.db.SysRole;
import com.itclass.auth.pojo.db.SysUser;
import lombok.Data;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class UserDetailsDTO implements Serializable {



    private Long userId;

    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 姓名
     */
    private String name;
    /**
     * 手机
     */
    private String phone;

    /**
     * 头像地址
     */
    private String headUrl;
    /**
     * 部门id
     */
    private Long deptId;
    /**
     * 岗位id
     */
    private Long postId;
    /**
     * 描述
     */
    private String description;
    /**
     * openId
     */
    private String openId;

    /**
     * 状态（1：正常 0：停用）
     */
    private Integer status;
    /**
     * 账号是否启用
     */

    private boolean enabled;


    private List<String> roles;

    public UserDetailsDTO() {

    }

    public static UserDetailsDTO buildUserDetail(AuthUserDetails authUser) {
        UserDetailsDTO userDetailsDTO = new UserDetailsDTO();
        userDetailsDTO.setUserId(authUser.getUserId());
        userDetailsDTO.setName(authUser.getName());
        userDetailsDTO.setUsername(authUser.getUsername());
        userDetailsDTO.setStatus(authUser.getStatus());
        userDetailsDTO.setEnabled(authUser.isEnabled());
        userDetailsDTO.setHeadUrl(authUser.getHeadUrl());
        userDetailsDTO.setDeptId(authUser.getDeptId());
        userDetailsDTO.setPhone(authUser.getPhone());
        userDetailsDTO.setDescription(authUser.getDescription());
        List<String> roleList = authUser.getRoles();

        userDetailsDTO.setRoles(roleList);

        return userDetailsDTO;
    }

}
